package foodmaterial.action;

import foodmaterial.config.ChoiceDataSource;
import foodmaterial.dto.StatisticsConsumeDto;
import foodmaterial.dto.StatisticsPurchaseDto;
import foodmaterial.entity.JsonResult;
import foodmaterial.entity.ResultCode;
import foodmaterial.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/api/statistics")
@RestController
@CrossOrigin(allowCredentials = "true")
public class StatisticsAction extends BaseAction {

    @Autowired
    private StatisticsService service ;

    @PostMapping("/querySupplyFoodMaterialByDay")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySupplyFoodMaterialByDay(
          @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySupplyFoodMaterialByDay(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySupplyFoodMaterialByMonth")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySupplyFoodMaterialByMonth(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySupplyFoodMaterialByMonth(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySupplyRecipeByDay")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySupplyRecipeByDay(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySupplyRecipeByDay(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySupplyRecipeByMonth")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySupplyRecipeByMonth(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySupplyRecipeByMonth(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySupplyFoodMaterialByTop")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySupplyFoodMaterialByTop(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySupplyFoodMaterialByTop(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySupplyRecipeByTop")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySupplyRecipeByTop(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySupplyRecipeByTop(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySaleByDay")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySaleByDay(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySaleByDay(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySaleByMonth")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySaleByMonth(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySaleByMonth(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryRecipeSaleByDay")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryRecipeSaleByDay(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.queryRecipeSaleByDay(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryRecipeSaleByMonth")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryRecipeSaleByMonth(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.queryRecipeSaleByMonth(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/querySaleByTop")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> querySaleByTop(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.querySaleByTop(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryRecipeSaleByTop")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryRecipeSaleByTop(
            @RequestBody StatisticsConsumeDto dto) {
        List<Map<String,Object>> result = service.queryRecipeSaleByTop(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryPurchaseFoodMaterialByDay")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryPurchaseFoodMaterialByDay(
            @RequestBody StatisticsPurchaseDto dto) {
        List<Map<String,Object>> result = service.queryPurchaseFoodMaterialByDay(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryPurchaseFoodMaterialByMonth")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryPurchaseFoodMaterialByMonth(
            @RequestBody StatisticsPurchaseDto dto) {
        List<Map<String,Object>> result = service.queryPurchaseFoodMaterialByMonth(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryPurchaseByDay")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryPurchaseByDay(
            @RequestBody StatisticsPurchaseDto dto) {
        List<Map<String,Object>> result = service.queryPurchaseByDay(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @PostMapping("/queryPurchaseByMonth")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryPurchaseByMonth(
            @RequestBody StatisticsPurchaseDto dto) {
        List<Map<String,Object>> result = service.queryPurchaseByMonth(dto) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

    @GetMapping("/queryPerformance")
    @ChoiceDataSource
    public JsonResult<List<Map<String,Object>>> queryPerformance(
            @RequestParam("beginSupplyDate") String beginSupplyDate,
            @RequestParam("endSupplyDate") String endSupplyDate,
            @RequestParam("choice") String choice) {
        List<Map<String,Object>> result = null ;
        if ("1".equals(choice))
            result = service.queryMasterPerformance(beginSupplyDate,endSupplyDate) ;
        else if ("2".equals(choice))
            result = service.queryDriverPerformance(beginSupplyDate,endSupplyDate) ;
        else
            result = service.queryTeamPerformance(beginSupplyDate,endSupplyDate) ;
        return new JsonResult(true, ResultCode.SUCCESS,result) ;
    }

}
